package bishi.xiaohongshu;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @Classname Main2
 * @Description TODO
 * @Date 2021/9/18 10:18
 * @Created by ASUS
 */
public class Main2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        scanner.nextLine();
        List<Integer> data = Arrays.stream(scanner.nextLine().split(" ")).map(Integer::parseInt).collect(Collectors.toList());
        scanner.close();
        List<Integer> array1 = new ArrayList<>(data);
        List<Integer> array2 = new ArrayList<>(data);
        array1.sort(Comparator.naturalOrder());
        array2.sort(Comparator.reverseOrder());
        System.out.println(Math.min(cnt(data, array1), cnt(data, array2)));
    }

    public static int cnt(List<Integer> src, List<Integer> data) {
        Map<Integer, Integer> map = new HashMap<>();
        ArrayList<Integer> array = new ArrayList<>(data);
        for (int i = 0; i < src.size(); i++) {
            map.put(array.get(i), i);
        }
        int cnt = 0;
        for (int i = 0; i < src.size(); i++) {
            if (src.get(i).equals(array.get(i))) continue;
            int  t = array.get(i);
            array.set(i, array.get(map.get(src.get(i))));
            array.set(map.get(src.get(i)), t);
            cnt++;
        }
        return cnt;
    }
}
